home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Visual Database / Visual BASIC 5.0 (Ent. Edition) / Vb5ent Extractor.EXE / VB / SAMPLES / COMPTOOL / ACTVCOMP / COFFEE / CWFORM1.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-11-27  |  5.8 KB  |  170 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "CoffeeWatch2"
  4.    ClientHeight    =   3765
  5.    ClientLeft      =   1800
  6.    ClientTop       =   1500
  7.    ClientWidth     =   4365
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   3765
  10.    ScaleWidth      =   4365
  11.    Begin VB.CommandButton cmdMT 
  12.       Caption         =   "&Multithreading Demo"
  13.       Height          =   375
  14.       Left            =   600
  15.       TabIndex        =   4
  16.       Top             =   3240
  17.       Width           =   3255
  18.    End
  19.    Begin VB.ListBox lstCallBacks 
  20.       Height          =   2235
  21.       Left            =   2280
  22.       TabIndex        =   3
  23.       Top             =   840
  24.       Width           =   1935
  25.    End
  26.    Begin VB.CommandButton cmdCallBacks 
  27.       Caption         =   "Start Receiving &Call-Backs"
  28.       Height          =   615
  29.       Left            =   2280
  30.       TabIndex        =   1
  31.       Top             =   120
  32.       Width           =   1935
  33.    End
  34.    Begin VB.CommandButton cmdEvents 
  35.       Caption         =   "Start Receiving CoffeeReady &Events"
  36.       Height          =   615
  37.       Left            =   120
  38.       TabIndex        =   0
  39.       Top             =   120
  40.       Width           =   1935
  41.    End
  42.    Begin VB.ListBox lstEvents 
  43.       Height          =   2235
  44.       Left            =   120
  45.       TabIndex        =   2
  46.       Top             =   840
  47.       Width           =   1935
  48.    End
  49. Attribute VB_Name = "Form1"
  50. Attribute VB_GlobalNameSpace = False
  51. Attribute VB_Creatable = False
  52. Attribute VB_PredeclaredId = True
  53. Attribute VB_Exposed = False
  54. Option Explicit
  55. ' Module-level storage for the shared
  56. '   CoffeeMonitor object.  The variable
  57. '   is declared WithEvents so that the
  58. '   CoffeeMonitor's events can be
  59. '   handled.
  60. Private WithEvents mwcmnEvents As CoffeeMonitor
  61. Attribute mwcmnEvents.VB_VarHelpID = -1
  62. ' Connector object used to obtain a
  63. '   reference to the shared CoffeeMonitor.
  64. Private mcctEvents As Connector
  65. ' Module-level storage for a reference
  66. '   to the CoffeeMonitor2 object used in
  67. '   the Call-Back Method demo.
  68. Private mcm2CallBacks As CoffeeMonitor2
  69. ' Storage for a reference to the call-back
  70. '   object.
  71. Private mNotifyMe As New NotifyMe
  72. ' Command button used to turn event reception
  73. '   on and off.
  74. Private Sub cmdEvents_Click()
  75.     Static blnInUse As Boolean
  76.     If blnInUse Then
  77.         ' Setting a WithEvents variable to Nothing
  78.         '   disconnects the object from its event
  79.         '   procedures, so that no more events are
  80.         '   received.
  81.         Set mwcmnEvents = Nothing
  82.         '
  83.         ' Dispose of the Connector object.
  84.         Set mcctEvents = Nothing
  85.         cmdEvents.Caption = "Start Receiving CoffeeReady Events"
  86.     Else
  87.         Set mcctEvents = New Connector
  88.         '
  89.         ' The Connector object supplies a reference
  90.         '   to the shared CoffeeMonitor.  When the
  91.         '   reference is place in the WithEvents
  92.         '   variable, the object is connected to its
  93.         '   event procedure, so that CoffeeWatch can
  94.         '   begin receiving events.
  95.         Set mwcmnEvents = mcctEvents.CoffeeMonitor
  96.         cmdEvents.Caption = "STOP Receiving CoffeeReady Events"
  97.     End If
  98.     blnInUse = True Xor blnInUse
  99. End Sub
  100. ' Command button used to turn call-backs on
  101. '   and off.
  102. Private Sub cmdCallBacks_Click()
  103.     Static blnInUse As Boolean
  104.     Dim ct2 As New Connector2
  105.     If blnInUse Then
  106.         ' Tell CoffeeMonitor2 that call-backs
  107.         '   are no longer desired.
  108.         Call mcm2CallBacks.CeaseCallBacks(mNotifyMe)
  109.         '
  110.         ' Release the shared copy of CoffeeMonitor2.
  111.         Set mcm2CallBacks = Nothing
  112.         cmdCallBacks.Caption = "Start Receiving Call-Backs"
  113.     Else
  114.         ' Obtain a Connector2 object, and use it to
  115.         '   get a reference to the shared copy of
  116.         '   CoffeeMonitor2.
  117.         Set ct2 = New Connector2
  118.         Set mcm2CallBacks = ct2.CoffeeMonitor2
  119.         '
  120.         ' Tell CoffeeMonitor2 to begin making calls
  121.         '   to the NotifyMe object (the object is
  122.         '   implicitly created here, because the
  123.         '   variable is declared As New).
  124.         Call mcm2CallBacks.TellMeReady(mNotifyMe)
  125.         cmdCallBacks.Caption = "STOP Receiving Call-Backs"
  126.     End If
  127.     blnInUse = True Xor blnInUse
  128. End Sub
  129. Private Sub cmdMT_Click()
  130.     ' When switching to the multithreading
  131.     '   demo, the call-backs and events should
  132.     '   be disabled.  Ask the user if its okay
  133.     '   to do that.  If the answer is vbNo,
  134.     '   go ahead and start the multithreading
  135.     '   demo anyway.
  136.     If (Not mwcmnEvents Is Nothing) Or _
  137.             (Not mcm2CallBacks Is Nothing) Then
  138.         Select Case MsgBox("Event and Call-Back notifications should be shut down before beginning the processor-intensive threading demo.  Shut them down now?", _
  139.                 vbYesNoCancel, "Start Multithreading Demo")
  140.             Case vbYes
  141.                 ' This doesn't unload the form,
  142.                 '   it just stops the demos.
  143.                 Call Form_Unload(False)
  144.             Case vbCancel
  145.                 Exit Sub
  146.         End Select
  147.     End If
  148.     cmdMT.Enabled = False
  149.     frmThread.Show vbModeless
  150. End Sub
  151. ' Shut down any running demos.
  152. Private Sub Form_Unload(Cancel As Integer)
  153.     If Not mwcmnEvents Is Nothing Then
  154.         Call cmdEvents_Click
  155.     End If
  156.     If Not mcm2CallBacks Is Nothing Then
  157.         Call cmdCallBacks_Click
  158.     End If
  159. End Sub
  160. ' When the CoffeeMonitor object sends a
  161. '   CoffeeReady event, add it to the list
  162. '   box.  If there are more than ten items
  163. '   in the list box, delete the oldest.
  164. Private Sub mwcmnEvents_CoffeeReady()
  165.     With lstEvents
  166.         .AddItem Format$(Now, "ddd hh:mm:ss"), 0
  167.         If .ListCount > 10 Then .RemoveItem 10
  168.     End With
  169. End Sub
  170.